using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Typing_GUI.CLASS;

namespace Typing_GUI
{
    public partial class frmAdmin : Form
    {
        public int userID;
        public int flag = 0;
        public frmAdmin()
        {
            InitializeComponent();
        }

        private void MakeVisibleAgain(object sender, FormClosedEventArgs e)
        {
            this.Visible = true;
        }

        private void btnManageLessons_Click(object sender, EventArgs e)
        {
            frmManageLesson_Admin frm = new frmManageLesson_Admin();
            frm.FormClosed += new FormClosedEventHandler(MakeVisibleAgain);
            frm.userId = userID;
            frm.Show();
            this.Visible = false;
        }

        void frm_FormClosed(object sender, FormClosedEventArgs e)
        {
            throw new Exception("The method or operation is not implemented.");
        }

        private void btnManageUsers_Click(object sender, EventArgs e)
        {
            frmManageUsers frm = new frmManageUsers();
            frm.FormClosed += new FormClosedEventHandler(MakeVisibleAgain);
            frm.userID = userID;
            frm.Show();
            this.Visible = false;
        }

        private void btnInfomation_Click(object sender, EventArgs e)
        {
            frmInformation  frm = new frmInformation();
            frm.FormClosed += new FormClosedEventHandler(MakeVisibleAgain);
            frm.userID = userID;
            frm.Show();
            this.Visible = false;
        }

        private void btnQuitGame_Click(object sender, EventArgs e)
        {
                this.Close(); 
        }

        private void frmAdmin_Load(object sender, EventArgs e)
        {
            string tenNguoiDung = CNguoiDung.LoadThongTinNguoiDung(userID, pbAvatar, pbCapDo);
            lblHoTen.Text = tenNguoiDung;
        }

        private void btnManageExam_Click(object sender, EventArgs e)
        {
            frmManageExam frm = new frmManageExam();
            frm.FormClosed+=new FormClosedEventHandler(MakeVisibleAgain);
            frm.userID = userID;
            frm.Show();
        }

        private void frmAdmin_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (flag == 0)
            {
                if (MessageBox.Show("Do you want to exit game ?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                    e.Cancel = true;
                else
                {
                    foreach (Form frm in Application.OpenForms)
                    {
                        if (frm is frmLogin)
                        {
                            ((frmLogin)frm).Close();
                            break;

                        }
                    }

                }
            }
        }

        private void lklblLogout_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            flag = 1;
            this.Close();
        }
    }
}